<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.3.5 - src/ltm.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - ltm.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.3.5</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">68</td>
            <td class="headerCovTableEntry">68</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:17</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: ltm.c,v 2.38.1.1 2017/04/19 17:39:34 roberto Exp $
<span class="lineNum">       3 </span>            : ** Tag methods
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define ltm_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;ldebug.h&quot;
<span class="lineNum">      18 </span>            : #include &quot;ldo.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;lstring.h&quot;
<span class="lineNum">      22 </span>            : #include &quot;ltable.h&quot;
<span class="lineNum">      23 </span>            : #include &quot;ltm.h&quot;
<span class="lineNum">      24 </span>            : #include &quot;lvm.h&quot;
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : 
<span class="lineNum">      27 </span>            : static const char udatatypename[] = &quot;userdata&quot;;
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            : LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
<span class="lineNum">      30 </span>            :   &quot;no value&quot;,
<span class="lineNum">      31 </span>            :   &quot;nil&quot;, &quot;boolean&quot;, udatatypename, &quot;number&quot;,
<span class="lineNum">      32 </span>            :   &quot;string&quot;, &quot;table&quot;, &quot;function&quot;, udatatypename, &quot;thread&quot;,
<span class="lineNum">      33 </span>            :   &quot;proto&quot; /* this last case is used for tests only */
<span class="lineNum">      34 </span>            : };
<span class="lineNum">      35 </span>            : 
<span class="lineNum">      36 </span>            : 
<span class="lineNum">      37 </span><span class="lineCov">        110 : void luaT_init (lua_State *L) {</span>
<span class="lineNum">      38 </span>            :   static const char *const luaT_eventname[] = {  /* ORDER TM */
<span class="lineNum">      39 </span>            :     &quot;__index&quot;, &quot;__newindex&quot;,
<span class="lineNum">      40 </span>            :     &quot;__gc&quot;, &quot;__mode&quot;, &quot;__len&quot;, &quot;__eq&quot;,
<span class="lineNum">      41 </span>            :     &quot;__add&quot;, &quot;__sub&quot;, &quot;__mul&quot;, &quot;__mod&quot;, &quot;__pow&quot;,
<span class="lineNum">      42 </span>            :     &quot;__div&quot;, &quot;__idiv&quot;,
<span class="lineNum">      43 </span>            :     &quot;__band&quot;, &quot;__bor&quot;, &quot;__bxor&quot;, &quot;__shl&quot;, &quot;__shr&quot;,
<span class="lineNum">      44 </span>            :     &quot;__unm&quot;, &quot;__bnot&quot;, &quot;__lt&quot;, &quot;__le&quot;,
<span class="lineNum">      45 </span>            :     &quot;__concat&quot;, &quot;__call&quot;
<span class="lineNum">      46 </span>            :   };
<span class="lineNum">      47 </span>            :   int i;
<span class="lineNum">      48 </span><span class="lineCov">       2750 :   for (i=0; i&lt;TM_N; i++) {</span>
<span class="lineNum">      49 </span><span class="lineCov">       2640 :     G(L)-&gt;tmname[i] = luaS_new(L, luaT_eventname[i]);</span>
<span class="lineNum">      50 </span><span class="lineCov">       2640 :     luaC_fix(L, obj2gco(G(L)-&gt;tmname[i]));  /* never collect these names */</span>
<span class="lineNum">      51 </span>            :   }
<span class="lineNum">      52 </span><span class="lineCov">        110 : }</span>
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span>            : 
<span class="lineNum">      55 </span>            : /*
<span class="lineNum">      56 </span>            : ** function to be used with macro &quot;fasttm&quot;: optimized for absence of
<span class="lineNum">      57 </span>            : ** tag methods
<span class="lineNum">      58 </span>            : */
<span class="lineNum">      59 </span><span class="lineCov">        751 : const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {</span>
<span class="lineNum">      60 </span><span class="lineCov">        751 :   const TValue *tm = luaH_getshortstr(events, ename);</span>
<span class="lineNum">      61 </span>            :   lua_assert(event &lt;= TM_EQ);
<span class="lineNum">      62 </span><span class="lineCov">        751 :   if (ttisnil(tm)) {  /* no tag method? */</span>
<span class="lineNum">      63 </span><span class="lineCov">        227 :     events-&gt;flags |= cast_byte(1u&lt;&lt;event);  /* cache this fact */</span>
<span class="lineNum">      64 </span><span class="lineCov">        227 :     return NULL;</span>
<span class="lineNum">      65 </span>            :   }
<span class="lineNum">      66 </span><span class="lineCov">        524 :   else return tm;</span>
<span class="lineNum">      67 </span>            : }
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span>            : 
<span class="lineNum">      70 </span><span class="lineCov">       8396 : const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {</span>
<span class="lineNum">      71 </span>            :   Table *mt;
<span class="lineNum">      72 </span><span class="lineCov">       8396 :   switch (ttnov(o)) {</span>
<span class="lineNum">      73 </span><span class="lineCov">        163 :     case LUA_TTABLE:</span>
<span class="lineNum">      74 </span><span class="lineCov">        163 :       mt = hvalue(o)-&gt;metatable;</span>
<span class="lineNum">      75 </span><span class="lineCov">        163 :       break;</span>
<span class="lineNum">      76 </span><span class="lineCov">        663 :     case LUA_TUSERDATA:</span>
<span class="lineNum">      77 </span><span class="lineCov">        663 :       mt = uvalue(o)-&gt;metatable;</span>
<span class="lineNum">      78 </span><span class="lineCov">        663 :       break;</span>
<span class="lineNum">      79 </span><span class="lineCov">       7570 :     default:</span>
<span class="lineNum">      80 </span><span class="lineCov">       7570 :       mt = G(L)-&gt;mt[ttnov(o)];</span>
<span class="lineNum">      81 </span>            :   }
<span class="lineNum">      82 </span><span class="lineCov">       8396 :   return (mt ? luaH_getshortstr(mt, G(L)-&gt;tmname[event]) : luaO_nilobject);</span>
<span class="lineNum">      83 </span>            : }
<span class="lineNum">      84 </span>            : 
<span class="lineNum">      85 </span>            : 
<span class="lineNum">      86 </span>            : /*
<span class="lineNum">      87 </span>            : ** Return the name of the type of an object. For tables and userdata
<span class="lineNum">      88 </span>            : ** with metatable, use their '__name' metafield, if present.
<span class="lineNum">      89 </span>            : */
<span class="lineNum">      90 </span><span class="lineCov">        332 : const char *luaT_objtypename (lua_State *L, const TValue *o) {</span>
<span class="lineNum">      91 </span>            :   Table *mt;
<span class="lineNum">      92 </span><span class="lineCov">        332 :   if ((ttistable(o) &amp;&amp; (mt = hvalue(o)-&gt;metatable) != NULL) ||</span>
<span class="lineNum">      93 </span><span class="lineCov">        332 :       (ttisfulluserdata(o) &amp;&amp; (mt = uvalue(o)-&gt;metatable) != NULL)) {</span>
<span class="lineNum">      94 </span><span class="lineCov">         29 :     const TValue *name = luaH_getshortstr(mt, luaS_new(L, &quot;__name&quot;));</span>
<span class="lineNum">      95 </span><span class="lineCov">         29 :     if (ttisstring(name))  /* is '__name' a string? */</span>
<span class="lineNum">      96 </span><span class="lineCov">         29 :       return getstr(tsvalue(name));  /* use it as type name */</span>
<span class="lineNum">      97 </span>            :   }
<span class="lineNum">      98 </span><span class="lineCov">        303 :   return ttypename(ttnov(o));  /* else use standard type name */</span>
<span class="lineNum">      99 </span>            : }
<span class="lineNum">     100 </span>            : 
<span class="lineNum">     101 </span>            : 
<span class="lineNum">     102 </span><span class="lineCov">         56 : void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1,</span>
<span class="lineNum">     103 </span>            :                   const TValue *p2, TValue *p3, int hasres) {
<span class="lineNum">     104 </span><span class="lineCov">         56 :   ptrdiff_t result = savestack(L, p3);</span>
<span class="lineNum">     105 </span><span class="lineCov">         56 :   StkId func = L-&gt;top;</span>
<span class="lineNum">     106 </span><span class="lineCov">         56 :   setobj2s(L, func, f);  /* push function (assume EXTRA_STACK) */</span>
<span class="lineNum">     107 </span><span class="lineCov">         56 :   setobj2s(L, func + 1, p1);  /* 1st argument */</span>
<span class="lineNum">     108 </span><span class="lineCov">         56 :   setobj2s(L, func + 2, p2);  /* 2nd argument */</span>
<span class="lineNum">     109 </span><span class="lineCov">         56 :   L-&gt;top += 3;</span>
<span class="lineNum">     110 </span><span class="lineCov">         56 :   if (!hasres)  /* no result? 'p3' is third argument */</span>
<span class="lineNum">     111 </span><span class="lineCov">          4 :     setobj2s(L, L-&gt;top++, p3);  /* 3rd argument */</span>
<span class="lineNum">     112 </span>            :   /* metamethod may yield only when called from Lua code */
<span class="lineNum">     113 </span><span class="lineCov">         56 :   if (isLua(L-&gt;ci))</span>
<span class="lineNum">     114 </span><span class="lineCov">         55 :     luaD_call(L, func, hasres);</span>
<span class="lineNum">     115 </span>            :   else
<span class="lineNum">     116 </span><span class="lineCov">          1 :     luaD_callnoyield(L, func, hasres);</span>
<span class="lineNum">     117 </span><span class="lineCov">         51 :   if (hasres) {  /* if has result, move it to its place */</span>
<span class="lineNum">     118 </span><span class="lineCov">         49 :     p3 = restorestack(L, result);</span>
<span class="lineNum">     119 </span><span class="lineCov">         49 :     setobjs2s(L, p3, --L-&gt;top);</span>
<span class="lineNum">     120 </span>            :   }
<span class="lineNum">     121 </span><span class="lineCov">         51 : }</span>
<span class="lineNum">     122 </span>            : 
<span class="lineNum">     123 </span>            : 
<span class="lineNum">     124 </span><span class="lineCov">        310 : int luaT_callbinTM (lua_State *L, const TValue *p1, const TValue *p2,</span>
<span class="lineNum">     125 </span>            :                     StkId res, TMS event) {
<span class="lineNum">     126 </span><span class="lineCov">        310 :   const TValue *tm = luaT_gettmbyobj(L, p1, event);  /* try first operand */</span>
<span class="lineNum">     127 </span><span class="lineCov">        310 :   if (ttisnil(tm))</span>
<span class="lineNum">     128 </span><span class="lineCov">        286 :     tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */</span>
<span class="lineNum">     129 </span><span class="lineCov">        310 :   if (ttisnil(tm)) return 0;</span>
<span class="lineNum">     130 </span><span class="lineCov">         32 :   luaT_callTM(L, tm, p1, p2, res, 1);</span>
<span class="lineNum">     131 </span><span class="lineCov">         32 :   return 1;</span>
<span class="lineNum">     132 </span>            : }
<span class="lineNum">     133 </span>            : 
<span class="lineNum">     134 </span>            : 
<span class="lineNum">     135 </span><span class="lineCov">        196 : void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,</span>
<span class="lineNum">     136 </span>            :                     StkId res, TMS event) {
<span class="lineNum">     137 </span><span class="lineCov">        196 :   if (!luaT_callbinTM(L, p1, p2, res, event)) {</span>
<span class="lineNum">     138 </span><span class="lineCov">        172 :     switch (event) {</span>
<span class="lineNum">     139 </span><span class="lineCov">          9 :       case TM_CONCAT:</span>
<span class="lineNum">     140 </span><span class="lineCov">          9 :         luaG_concaterror(L, p1, p2);</span>
<span class="lineNum">     141 </span>            :       /* call never returns, but to avoid warnings: *//* FALLTHROUGH */
<span class="lineNum">     142 </span><span class="lineCov">         74 :       case TM_BAND: case TM_BOR: case TM_BXOR:</span>
<span class="lineNum">     143 </span>            :       case TM_SHL: case TM_SHR: case TM_BNOT: {
<span class="lineNum">     144 </span>            :         lua_Number dummy;
<span class="lineNum">     145 </span><span class="lineCov">         74 :         if (tonumber(p1, &amp;dummy) &amp;&amp; tonumber(p2, &amp;dummy))</span>
<span class="lineNum">     146 </span><span class="lineCov">         11 :           luaG_tointerror(L, p1, p2);</span>
<span class="lineNum">     147 </span>            :         else
<span class="lineNum">     148 </span><span class="lineCov">         63 :           luaG_opinterror(L, p1, p2, &quot;perform bitwise operation on&quot;);</span>
<span class="lineNum">     149 </span>            :       }
<span class="lineNum">     150 </span>            :       /* calls never return, but to avoid warnings: *//* FALLTHROUGH */
<span class="lineNum">     151 </span><span class="lineCov">         89 :       default:</span>
<span class="lineNum">     152 </span><span class="lineCov">         89 :         luaG_opinterror(L, p1, p2, &quot;perform arithmetic on&quot;);</span>
<span class="lineNum">     153 </span>            :     }
<span class="lineNum">     154 </span>            :   }
<span class="lineNum">     155 </span><span class="lineCov">         24 : }</span>
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span>            : 
<span class="lineNum">     158 </span><span class="lineCov">        114 : int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,</span>
<span class="lineNum">     159 </span>            :                       TMS event) {
<span class="lineNum">     160 </span><span class="lineCov">        114 :   if (!luaT_callbinTM(L, p1, p2, L-&gt;top, event))</span>
<span class="lineNum">     161 </span><span class="lineCov">        106 :     return -1;  /* no metamethod */</span>
<span class="lineNum">     162 </span>            :   else
<span class="lineNum">     163 </span><span class="lineCov">          8 :     return !l_isfalse(L-&gt;top);</span>
<span class="lineNum">     164 </span>            : }
<span class="lineNum">     165 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
